package com.example.lifecycledemo.observer;

import com.example.lifecycledemo.MyLocationListener;

import androidx.lifecycle.LifecycleService;

/**
 * Created by xiuzhizhu
 * Date: 2020/11/29
 */

// 实现了 LifecycleOwner 接口的 Service。LifecycleService 可以直接调用 getLifecycle() 获取 Lifecycle 对象
class MyLifecycleService extends LifecycleService {

    private MyLocationListener myLocationListener;

    @Override
    public void onCreate() {
        super.onCreate();

        myLocationListener = new MyLocationListener(this, new MyLocationListener.OnLocationChangedListener() {
            @Override
            public void onChange(double latitude, double longitude) {
                // 位置变更 回调函数
            }
        });

        getLifecycle().addObserver(myLocationListener);
    }
}
